Repository navigation
fix(gemini): skip undownloadable history images instead of failing the turn - #10894
Conversation
There was a problem hiding this comment.
Hey - I've reviewed your changes and they look great!
Linked issues
#10884 [Bug] OneBot 图片下载失败被误判为模型故障,导致回复中断或触发模型回退 · 3 of 3 met
| # | Requirement | Status | Notes |
|---|---|---|---|
| 1 | Treat failed image downloads as recoverable image-input failures, not model-request failures. | ✅ Met | The media resolver now catches the declared recoverable image errors in non-strict mode, including DownloadFileHTTPError, while preserving propagation for undeclared errors. |
| 2 | Skip only the failed image, preserving the user’s text and other valid images so the model call can proceed. | ✅ Met | Gemini’s payload processing skips a recoverably unavailable image and continues processing the remaining parts; if no parts remain, it adds a placeholder text part. |
| 3 | Do not trigger a fallback provider because an image in the conversation history could not be downloaded. | ✅ Met | The Gemini boundary handles recoverable image errors before they reach the agent runner; the added runner test checks that the primary provider is called and the fallback is not. |
Sourcery assessment
Approved.
be10e5b to
6cfb39c
Compare
Linked issuesChecked at commit c4d84a4 #10884 [Bug] OneBot 图片下载失败被误判为模型故障,导致回复中断或触发模型回退 · 3 of 3 met
|
|
Codecov Report❌ Patch coverage is
📢 Thoughts on this report? Let us know! |
aa72c81 to
b543d8e
Compare
|
Rebased onto latest Local Verification
建议合并顺序
|
|
Hi @camera-2018, this PR has been rebased cleanly onto latest |
mantoujun12
left a comment
There was a problem hiding this comment.
The core fix is correct: DownloadFileHTTPError now degrades in non-strict resolution, and Gemini skips the failed history image instead of failing the turn or switching to the fallback provider. I reproduced the bug on the merge base and confirmed it is gone on this branch; I'm only blocking on the two points below.
- The description says 5 files / 349 insertions and lists six regression tests, but the actual diff is 2 files / +44/-12 with zero test changes. Looks like the tests were dropped in a force-push. Please restore them or update the description, otherwise nothing stops someone from narrowing the catch back to (OSError, ValueError) later.
- The fix only covers images. process_audio_url still uses strict=True and raises, so a single undownloadable history audio still aborts the turn or triggers the fallback provider. Might be out of scope, but it should be called out explicitly or handled in a follow-up.
Approving once the tests are back, or once the description is corrected and the audio gap is explicitly accepted.
b543d8e to
c4d84a4
Compare
|
Thanks for reproducing the issue and catching both points, @mantoujun12! Both blockers are now resolved in
Ready for re-review whenever you have a moment — thank you! |
Fixes #10884.
Problem
When a Gemini provider replays conversation history that contains an image
reference (for example an OneBot image URL), a failed download of that single
image is treated as a failure of the main model:
DownloadFileHTTPError, orprovider, even though only one image in the replayed history could not be
materialized.
Root cause
The real failure path is:
Two independent defects stack up on that path:
DownloadFileHTTPError(astrbot/core/utils/io.py) subclassesRuntimeError, and aiohttp'sClientError,SyntaxError,EOFErrorandstruct.errorare likewise notOSError/ValueError.MediaResolver.to_base64_dataonly caught
(OSError, ValueError), so the documented "an image that cannotbe materialized degrades to
Nonein non-strict mode" behavior never appliedto download failures — even though
is_recoverable_image_error()explicitlylists
DownloadFileHTTPError.resolve_image_urlpassedstrict=Trueand turned aNoneresult into aValueError, so even a corrected resolver could not degrade: it wouldnecessarily raise, and the runner's per-candidate
except Exceptiontranslated that into "the model failed".
This is a classification bug, not a design decision. The same repository
already degrades one image at a time in
astr_main_agent.py([Image unavailable]text part and continue), inprovider/entities.py, and inGemini's own
assemble_contextfor the current turn. Only the Gemini historyreplay path and the
media_utilscatch were inconsistent, so no new contractor configuration switch is needed.
Behavior after the fix
MediaResolver.to_base64_data(strict=True)still raises for an image thatcannot be materialized; strict callers are unchanged.
OSError,ValueError,SyntaxError,EOFError,struct.error,ClientError,DownloadFileHTTPError) degrades toNone. Unrecoverable failures such asresource exhaustion (
ENOMEM,EMFILE,ENFILE) and programming errorsstill propagate.
the declared-recoverable errors at its own boundary, the same shape
astr_main_agentuses: one warning carrying the exception type and thelog-safe reference, then skip only that image. A turn that still has text
keeps exactly that text; only a turn left with no parts gets a single space
part so the
UserContentremains valid and non-empty. ANoneresult fromstrict resolution takes the same warning-and-skip path via an explicit
is Nonebranch.so the primary provider is used and no fallback provider is switched in.
Scope & safety
images only (fixing [Bug] OneBot 图片下载失败被误判为模型故障,导致回复中断或触发模型回退 #10884).
process_audio_urlingemini_source.pystilluses
strict=Trueand raises on undownloadable history audio; graceful audiodegradation is accepted as a separate follow-up PR.
Changed files
astrbot/core/provider/sources/gemini_source.py(+38 / -9)astrbot/core/utils/media_utils.py(+6 / -3)tests/test_gemini_source.py(+25 / -0)tests/test_media_utils.py(+17 / -0)Diff summary: 4 files changed, 86 insertions(+), 12 deletions(-).
Tests
Compact regression tests pinning both boundaries (
42lines total):tests/test_media_utils.py::test_image_base64_data_degrades_download_http_error:verifies a mocked
download_fileraisingDownloadFileHTTPErrordegrades toNonewhenstrict=False, still raises whenstrict=True, and an undeclaredRuntimeErrorstill propagates whenstrict=False.tests/test_gemini_source.py::test_gemini_prepare_conversation_skips_undownloadable_images:verifies
_prepare_conversationskips an undownloadable history image(
DownloadFileHTTPError) while keeping the turn's text, produces a non-emptyUserContentplaceholder (" ") when an image-only turn resolves to no data,and still propagates an unrecoverable
RuntimeError.Verification:
tests/test_media_utils.py,tests/test_gemini_source.py,tests/test_tool_loop_agent_runner.py): 199 passed, 1 skipped.ruff format --check .andruff check .: passed (0issues).Suggested merge order
Logically independent of
#10961,#11185, and#11298(all touch distinct sections ofastrbot/core/provider/sources/gemini_source.py). Suggested order: #10961 → #10894 → #11185 → #11298 (any order works).